#ifndef __CONFIG_ITOP4412_H
#define __CONFIG_ITOP4412_H

#include <configs/exynos4-common.h>

/**
 * 内存相关的配置
 */
#define CONFIG_SDRAM_SIZE       1   /*1G，则为1，2G，则为2*/

/* itop4412 has 4 bank of DRAM */
#define CONFIG_SYS_SDRAM_BASE		0x40000000
#define PHYS_SDRAM_1			    CONFIG_SYS_SDRAM_BASE

/*mem size*/
#define CONFIG_NR_DRAM_BANKS        4
#if CONFIG_SDRAM_SIZE == 1
#define SDRAM_BANK_SIZE				(256 << 20)	/* 256 MB */
#else
#define SDRAM_BANK_SIZE				(512 << 20)	/* 512 MB */
#endif

/* memtest works on */
#define CONFIG_SYS_MEMTEST_START    CONFIG_SYS_SDRAM_BASE
#define CONFIG_SYS_MEMTEST_END		(CONFIG_SYS_SDRAM_BASE + 0x6000000)
#define CONFIG_SYS_LOAD_ADDR		(CONFIG_SYS_SDRAM_BASE + 0x3E00000)

/*隐藏顶部*/
#define CONFIG_SYS_MEM_TOP_HIDE     (1 << 20)

/*stack*/
#define CONFIG_SYS_INIT_SP_ADDR		0x02040000

/*SDRAM init*/
#define CONFIG_MIU_4KBIT_INTERLEAVED
#define DRAM_CLK_400


/**
 * 环境变量相关的配置
 */
#define CONFIG_ENV_SIZE             (16 << 10) /* 16k */
#define CONFIG_SYS_MMC_ENV_DEV		0
#define CONFIG_SYS_MMC_IMG_LOAD_PART	1
#define CONFIG_MMCROOT			"/dev/ram"  

#define CONFIG_EXTRA_ENV_SETTINGS \
    "script=boot.scr\0" \
    "image=zImage\0" \
    "console=ttySAC2\0" \
    "baudrate=115200\0" \
    "boot_fdt=try\0" \
    "ip_dyn=yes\0" \
    "ipaddr=192.168.3.8\0" \
    "serverip=192.168.3.16\0" \
    "gatewayip=192.168.3.1\0" \
    "netmask=255.255.255.0\0" \
    "nfsroot=/home/sszl/arm/nfs/itop4412/root;\0" \
    "hostname=uboot\0" \
    "bootdelay=0\0" \
    "loadaddr=0x40008000\0" \
    "dtbaddr=0x44000000\0" \
    "fdt_addr=${dtbaddr}\0" \
    "dtbname="CONFIG_DEFAULT_DEVICE_TREE".dtb\0" \
    "fdt_file="CONFIG_DEFAULT_DEVICE_TREE".dtb\0" \
    "rdiskaddr=0x50000000\0" \
    "rdiskname=ramdiskfs\0" \
    "bootargs=initrd=0x50000040,0x4100000 root=/dev/ram rw init=/linuxrc console=ttySAC2,115200 earlyprintk\0" \
	"bootmenu_delay=3\0"\
	"bootmenu_0=Start kernel=run startlinux;\"\0" \
	"bootmenu_1=Net Start kernel(tftp)=run netboot;\0" \
	"bootmenu_2=NFS Start kernel=run nfsboot;\0" \
    "mmcroot=" CONFIG_MMCROOT " rootwait rw\0" \
	"mmcargs=setenv bootargs initrd=0x50000040,0x4100000 init=/linuxrc console=${console},${baudrate} earlyprintk" \
		"root=${mmcroot}\0" \
	"netargs=setenv bootargs initrd=0x50000040,0x4100000 init=/linuxrc console=${console},${baudrate} earlyprintk" \
		"root=/dev/nfs " \
		"ip=dhcp nfsroot=${serverip}:${nfsroot},v3,tcp\0" \
    "loadfdt=fatload mmc ${mmcdev}:${mmcpart} ${fdt_addr} ${fdt_file}\0" \
    "mmcboot=echo Booting from mmc ...; " \
		"run mmcargs; " \
		"if test ${boot_fdt} = yes || test ${boot_fdt} = try; then " \
			"if run loadfdt; then " \
				"bootz ${loadaddr} - ${fdt_addr}; " \
			"else " \
				"if test ${boot_fdt} = try; then " \
					"bootz; " \
				"else " \
					"echo WARN: Cannot load the DT; " \
				"fi; " \
			"fi; " \
		"else " \
			"bootz; " \
		"fi;\0" \
	"nfsboot="\
		"run netargs; " \
        "usb reset;usb reset; " \
		"setenv ipaddr 192.168.3.22;"\
		"setenv gatewayip 192.168.1.1;"\
		"setenv netmask 255.255.255.0;"\
		"nfs ${loadaddr} /home/sszl/arm/nfs/itop4412/${image};"\
		"nfs ${fdt_addr} /home/sszl/arm/nfs/itop4412/${fdt_file};"\
		"bootz ${loadaddr} - ${fdt_addr};\0"\
    "netboot=echo Booting from net ...; " \
		"run netargs; " \
        "usb reset;usb reset; " \
		"if test ${ip_dyn} = yes; then " \
			"setenv get_cmd dhcp; " \
		"else " \
			"setenv get_cmd tftp; " \
		"fi; " \
		"${get_cmd} ${image}; " \
		"if test ${boot_fdt} = yes || test ${boot_fdt} = try; then " \
			"if ${get_cmd} ${fdt_addr} ${fdt_file}; then " \
				"bootz ${loadaddr} - ${fdt_addr}; " \
			"else " \
				"if test ${boot_fdt} = try; then " \
					"bootz; " \
				"else " \
					"echo WARN: Cannot load the DT; " \
				"fi; " \
			"fi; " \
		"else " \
			"bootz; " \
		"fi;\0" \
	"findfdt="\
			"if test $fdt_file = undefined; then " \
				"if test $board_name = ITOP4412 && test $board_rev = EMMC; then " \
					"setenv fdt_file exynos4412-itop4412.dtb; fi; " \
				"if test $fdt_file = undefined; then " \
					"echo WARNING: Could not determine dtb to use; fi; " \
			"fi;\0" \
	"mmcdev="__stringify(CONFIG_SYS_MMC_ENV_DEV)"\0" \
	"mmcpart=" __stringify(CONFIG_SYS_MMC_IMG_LOAD_PART) "\0" \
	"bootscript=echo Running bootscript from mmc ...; " \
		"source\0" \
    "loadimage=fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${image}\0" \
	"loadbootscript=" \
	"fatload mmc ${mmcdev}:${mmcpart} ${loadaddr} ${script};\0" \
    "startlinux=" \
    "run findfdt;" \
    "mmc dev ${mmcdev};" \
    "mmc dev ${mmcdev}; if mmc rescan; then " \
        "if run loadbootscript; then " \
            "run bootscript; " \
        "else " \
            "if run loadimage; then " \
                "run mmcboot; " \
            "else run netboot; " \
            "fi; " \
        "fi; " \
    "else run netboot; fi\0"\

#define CONFIG_BOOTCOMMAND \
		"bootmenu 3"

/*
	"startlinux=" \
    "usb reset;usb reset;" \
    "tftpboot ${loadaddr} uImage;" \
    "tftpboot ${dtbaddr} ${dtbname};" \
    "tftpboot ${rdiskaddr} ${rdiskname};" \
    "bootm ${loadaddr} ${rdiskaddr}  ${dtbaddr};\0"\
*/

#define CONFIG_SYS_BOOTM_LEN 0x4000000


/**
 * SPL相关配置信息
 */
#define CONFIG_EXYNOS4X12		1
#define CONFIG_ITOP4412			1

/*SPL代码段基地址*/
#define CONFIG_SPL_TEXT_BASE	0x02023400

/*组件大小*/
#define CONFIG_SPL_MAX_FOOTPRINT	(14 * 1024)
#define BL1_SIZE					((8 << 10))		/* 8K */
#define BL2_SIZE 					((16 << 10))	/* 16K */
#define UBOOT_SIZE					((512 << 10))	/* 512K */

/* U-BOOT位置 */
#define BL2_START_OFFSET		((512 + BL1_SIZE + BL2_SIZE)/512)
#define BL2_SIZE_BLOC_COUNT		((UBOOT_SIZE / 512))

/* Power Down Modes */
#define S5P_CHECK_SLEEP			0x00000BAD
#define S5P_CHECK_DIDLE			0xBAD00000
#define S5P_CHECK_LPA			0xABAD0000

/**
 * 启动USB支持
 */
#define CONFIG_USB_EHCI_EXYNOS

#endif	/* __CONFIG_H */

